class StudentController:
    def __init__(self):
        self.__stu_list = []

    @property
    def stu_list(self):
        return self.__stu_list[:]

    def sort_student(self):
        """
            将学生列表按照成绩升序排序
        :return:
        """
        new_list = self.__stu_list[:]
        for i in range(0, len(new_list) - 1):
            for j in range(i + 1, len(new_list)):
                if new_list[i].score > new_list[j].score:
                    new_list[i], new_list[j] = new_list[j], new_list[i]
        return new_list

    def add_student(self, student):
        """
            新增学生
        :param student:
        :return:
        """
        id = self.__generate_id()
        student.id = id
        self.__stu_list.append(student)

    def __generate_id(self):
        """
            生成学生编号
            需求：生成编号的需求：新编号，是上次添加的对象编号多1
        :return:
        """
        return self.__stu_list[-1].id + 1 if len(self.__stu_list) > 0 else 1

    def delete_student_by_id(self, id):
        for student in self.__stu_list:
            if student.id == id:
                self.__stu_list.remove(student)
                return True
        return False

    def update_student(self, stu):
        for item in self.__stu_list:
            if item.id == stu.id:
                item.name = stu.name
                item.age = stu.age
                item.score = stu.score
                return True
        return False
